<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of welcome
 *
 * @author Obi
 */
class Admin_stock extends MY_Controller {

    function __construct() {
        parent::__construct();
        
        $cek_admin = $this->session->userdata('cek_admin');
        if (!$cek_admin)
            redirect("admin");

        $this->mstock = new M_stock();
    }

    function index() {

        $data['title'] = 'Data Stock';
		
        $data['list'] = $this->mstock->select_data();

        $data['isi'] = 'isi';
        $this->load->view('template_admin', $data);
    }

    function tambah() {

        $data['title'] = 'Add Stock';

        $data['id'] = "";
        $data['kode_katagori'] = "";
        $data['nama_katagori'] = "";

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function edit($id = NULL) {

        $data['title'] = 'Edit Stock';

        $dt = $this->mstock->where("id = '$id'")->get();

        $data['id'] = $dt->id;
        $data['symbol'] = $dt->symbol;
        $data['company'] = $dt->company;
        $data['industries'] = $dt->industries;

        $data['isi'] = 'form';
        $this->load->view('template_admin', $data);
    }

    function delete($id) {
        $this->mstock->delete($id);
        redirect("admin_stock");
    }

    function simpan() {
        $id = $this->input->post('id');

        $data = array(
            'symbol' => $this->input->post('symbol'),
            'company' => $this->input->post('company'),
            'industries' => $this->input->post('industries')
        );

        if ($id == "") {
            $this->mstock->insert($data);
            $this->mstock->insertLocstock($this->input->post('symbol'));
        } else {
            $this->mstock->update($data, $id);
        }

        redirect("admin_stock");
    }

}

?>
